// Copyright (c) 2007 Robin Boerdijk. All rights reserved.
//
// This software is licensed under the terms of the Microsoft Reciprocal License as described 
// in the file LICENSE.txt, which you should have received as part of this distribution. The 
// license terms are also available at http://www.opensource.org/licenses/ms-rl.html.

#ifndef wtk_Window_h_included
#define wtk_Window_h_included

#include "wtk/Geometry.h"
#include "wtk/Menu.h"
#include "wtk/win32.h"

#include <string>

#pragma warning (disable: 4355) // Prevent bogus warning C4355: 'this' : used in base member initializer list

namespace wtk
{
	class Window
	{
	public:

		const wchar_t * const className;

		Window * const parentWindow;

		DWORD style;

		DWORD styleEx;

		POINT position;

		SIZE size;

		HWND handle;

		HFONT font;

		Window(const wchar_t *className, Window *parentWindow);

		virtual ~Window();

		void Create(const wchar_t *title, HMENU menuHandle);

		void Destroy();

		void SetWindowPos(HWND insertAfterWindowHandle, UINT flags);

		HDWP DeferWindowPos(HDWP dwpHandle, HWND insertAfterWindowHandle, UINT flags);

		HFONT GetFont();

		SIZE GetTextBoxSize(const std::wstring &text);

		void DrawMenuBar() { win32::DrawMenuBar(this->handle); }

		void Show(int how) { win32::ShowWindow(this->handle, how); }

		void Update() { win32::UpdateWindow(this->handle); }

		bool IsEnabled() { return win32::IsWindowEnabled(this->handle) == TRUE; }

		void Disable() { win32::EnableWindow(this->handle, FALSE); }

		void Enable() { win32::EnableWindow(this->handle, TRUE); }

		void OpenClipboard() { win32::OpenClipboard(this->handle); }

		int GetText(wchar_t *buffer, int size) { return win32::GetWindowTextW(this->handle, buffer, size); }

		int GetTextLength() { return win32::GetWindowTextLengthW(this->handle); }

		std::wstring GetText();

	protected:

		virtual LRESULT ProcessMessage(HWND windowHandle, UINT message, WPARAM wParam, LPARAM lParam);

	private:

		static LRESULT CALLBACK SubclassProc(HWND, UINT, WPARAM, LPARAM, UINT_PTR, DWORD_PTR);

		LRESULT ProcessMenuCommandMessage(HMENU menuHandle, UINT selectedItemIndex);
	};
}

#endif